﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;

namespace JetRetail.Forms
{
    public partial class frmReportFromSertificate : Form
    {
        int iCheckKey;
        string sCheckNumber;
        decimal deTotalAmount, deCertificateAmount = 0;
        DrvFRLib.IDrvFR47 ShtrihM;
        JetRetailDB DB;
        int iContractor = 0;
        JetRetail.WorkSetting WorkSet;



        public frmReportFromSertificate(JetRetailDB DB, int iCheckKey, string sCheckNumber, decimal deTotalAmount, DrvFRLib.IDrvFR47 ShtrihM)
        {
            this.DB = DB;
            this.iCheckKey = iCheckKey;
            this.sCheckNumber = sCheckNumber;
            this.deTotalAmount = deTotalAmount;

            this.ShtrihM = ShtrihM;
            WorkSet = new WorkSetting();

            InitializeComponent();
        }

        private void frmReportFromSertificate_Load(object sender, EventArgs e)
        {
            dtPic.Value = System.DateTime.Now.Date;
        }

        private void btnRepShow_Click(object sender, EventArgs e)
        {
            PrintReportFromSertificate(dtPic.Value);
            Close();
        }

        private void PrintReportFromSertificate(DateTime dtVal)
        {
            int iTotal = 0;

            ShtrihM.UseReceiptRibbon = true;
            ShtrihM.UseJournalRibbon = false;
            //ShtrihM.PrintCliche();
            ShtrihM.StringForPrinting = "------------------------------------";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = "Отчет по сертификатам на " + dtVal.ToShortDateString();
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = "------------------------------------";
            ShtrihM.PrintString();

            ISingleResult<ПолучитьОтчетПоСертификатамResult> Lines = DB.GetReportFromSetificateOnDate(dtVal);
            foreach (ПолучитьОтчетПоСертификатамResult Line in Lines)
            {
                ShtrihM.StringForPrinting = Line.ВремяЗакрытия.ToString().Substring(11) + "     ";
                switch (Line.Контрагент.Value)
                {
                    case 1:
                        {
                            ShtrihM.StringForPrinting += "Дезира     ";
                        }
                        break;

                    case 2:
                        {
                            ShtrihM.StringForPrinting += "Дриант     ";
                        }
                        break;

                    case 3:
                        {
                            ShtrihM.StringForPrinting += "Дриант     ";
                        }
                        break;

                    case 4:
                        {
                            ShtrihM.StringForPrinting += "Ликва      ";
                        }
                        break;

                    case 5:
                        {
                            ShtrihM.StringForPrinting += "ОДК        ";
                        }
                        break;

                    case 6:
                        {
                            ShtrihM.StringForPrinting += "Фармин     ";
                        }
                        break;

                    case 7:
                        {
                            ShtrihM.StringForPrinting += "Фитобел    ";
                        }
                        break;

                    case 8:
                        {
                            ShtrihM.StringForPrinting += "Альфармед   ";
                        }
                        break;

                    case 9:
                        {
                            ShtrihM.StringForPrinting += "МашериИнвест";
                        }
                        break;

                    default:
                        {
                            ShtrihM.StringForPrinting += "???        ";
                        }
                        break;
                }
                iTotal += (int)Line.Сумма.Value;
                string sSum = "" + (int)Line.Сумма.Value;
                while (sSum.Length < 6) sSum = " " + sSum;
                ShtrihM.StringForPrinting += sSum + " руб.";
                ShtrihM.PrintString();
            }

            ShtrihM.StringForPrinting = "------------------------------------";
            ShtrihM.PrintString();
            string sTotal = "" + iTotal;
            while (sTotal.Length < 10) sTotal = " " + sTotal;
            ShtrihM.StringForPrinting = "             ИТОГО: " + sTotal + " руб.";
            //MessageBox.Show(ShtrihM.StringForPrinting);
            ShtrihM.PrintString();

            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = " ";
            ShtrihM.PrintString();

            ShtrihM.CutType = false;
            ShtrihM.CutCheck();

            ShtrihM.StringForPrinting = "            " + WorkSet.GetCopyCheckName();
            ShtrihM.PrintString();
            ShtrihM.StringForPrinting = "   ";
            ShtrihM.PrintString();
        }

    }
}
